<include file="__THEME__/public_header" />
<div class="content">
	<div class="wrap">
    	<div class="con_side">
        	<ul class="nav">
            	<li><a href="{:U('admin/Privilege/index')}">市级账号</a></li>
                <li><a href="{:U('admin/Privilege/show_area_user')}">区级账号</a></li>
                <li class="cursor"><a href="{:U('admin/Privilege/show_garden_user')}">园级账号</a></li>
            </ul>
        </div>
        <div class="con_main">
        	<div class="con_tit">
            	<ul class="con_link">
                    <li class="on"><a href="javascript:;">筛选</a></li>
                    <li><a href="{:u('admin/Privilege/create_garden_user')}">新建用户</a></li>
                </ul>
                <div class="search_wrap">
                	<input class="search_inp" id="uname" type="text" value="" placeholder="按园所名称搜索">
                    <input class="search_btn" type="submit" value="" onclick="select_filter();">
                </div>
            </div>
            <div class="con_box">
            	<ul class="slect_list2">
                    <li>
                        <div class="txt">选择省级：</div>
                        <div class="inp">
                            <select id="Province" onchange="selectArea(1);">
                                <option>----请选择----</option>
                                <volist name="province" id="province">
                                    <option value="{$province.area_id}">{$province.title}</option>
                                </volist>
                            </select>
                        </div>
                    </li>
                    <li>
                        <div class="txt">选择市级：</div>
                        <div class="inp">
                            <select id="City" onchange="selectArea(2);">
                                <option value="0">----请选择----</option>
                            </select>
                        </div>
                    </li>
                    <li>
                        <div class="txt">选择区级：</div>
                        <div class="inp">
                            <select id="Area">
                                <option value="0">----请选择----</option>
                            </select>
                        </div>
                    </li>
                </ul>
            	<div class="action_link tc small">
                	<a class="save" href="javascript:select_filter();">确定</a>
                </div>
            </div>
            <div class="con_tit">
                <table class="table table_title t5">
                  <tbody><tr>
                    <td>园名</td>
                    <td>类型</td>
                    <td>园所位置</td>
                    <td>登录名</td>
                    <td>密码</td>
                    <td>操作</td>
                  </tr>
                </tbody></table>
            </div>
            <div class="con_box">
                <table class="table table_list t5_3">
                  <tbody>
                    <if condition="$garden_user['data']">
                      <volist name = "garden_user['data']" id="user">
                          <tr>
                            <td id="uname{$user.uid}">{$user.uname}</td>
                            <td id="type{$user.uid}">
                              <if condition="$user['school']['type'] eq 1">市级示范</if>
                              <if condition="$user['school']['type'] eq 2">区级示范</if>
                              <if condition="$user['school']['type'] eq 3">一级一类</if>
                              <if condition="$user['school']['type'] eq 4">一级二类</if>
                              <if condition="$user['school']['type'] eq 5">二级一类</if>
                              <if condition="$user['school']['type'] eq 6">二级二类</if>
                              <if condition="$user['school']['type'] eq 7">其他</if>
                            </td>
                            <td>
                              <if condition="$user['school']['location'] eq 1">市内</if>
                              <if condition="$user['school']['location'] eq 2">郊区</if>
                            </td>
                            <td>{$user.email}</td>
                            <td id="pwd{$user.uid}">{$user.pwd}</td>
                            <td>
                                <a href="javascript:updateUser({$user.uid});">修改</a>
                                <a href="javascript:delUser({$user.uid});">删除</a>
                            </td>
                          </tr>
                      </volist>
                      <else/>
                      暂无用户
                    </if>
                </tbody>
                <if condition="$garden_user['html']">
                <tr>
                    <td colspan="4">{$garden_user.html}</td>
                </tr>
                </if>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="pop_wrap" id="pop_wrap" style="display:none;">
  <div class="pop_box">
      <div class="pop_head"><a class="close" href="javascript:close();">X</a>用户信息修改</div>
        <div class="pop_body">
          <dl class="diapei_dl">
              <dt>用户名：</dt>
                <dd>
                   <input type="text" id="name">
                </dd>
            </dl>
            <dl class="diapei_dl">
              <dt>级别：</dt>
                <dd>
                  <select name="type" id="type"></select>
                </dd>
            </dl>
            <dl class="diapei_dl">
              <dt>密码：</dt>
                <dd>
                    <input type="text" id="pwd">
                </dd>
            </dl>
        </div>
        <ul class="pop_foot">
          <li><a href="javascript:close();">取消</a></li>
          <li><a href="javascript:doUpdateUser();">确定</a></li>
        </ul>
    </div>
</div>
<input type="hidden" id="uid">
<script>
    function selectArea(type){
        if(type==1){
            var pid=$("#Province").val();
            var name="City";
        }else{
            var pid=$("#City").val();
            var name="Area";
        }
        if(pid>0){
            $.ajax({
              type: "GET",
              url:"{:U('public/TestData/getArea')}",
              data:"pid="+pid,
              dataType:"json",
              success:function(data){
                $("#"+name).html("");
                $("#"+name).append("<option value='0'>----请选择----</option>");
                $.each(data,function(i,item){
                  $("#"+name).append("<option value='"+item.area_id+"'>"+item.title+"</option>");
                }); 
              }
            });
        }
    }
    function select_filter(){
        var Area=$("#Area").val();
        var uname=$("#uname").val();
        window.location.href = "{:U('admin/Privilege/show_garden_user')}"+"&AreaId="+Area+"&uname="+uname; 

    }
    function delUser(id){
        if(confirm("你确定要删除改用户？")){
            $.ajax({
              type: "POST",
              url:"{:U('admin/Privilege/delUser')}",
              data:"id="+id,
              dataType:"text",
              success:function(data){
                if(isNaN(data)){
                  alert(data);
                }else{  
                  select_filter();
                }
              }
            });
        }
    }
    function updateUser(id){
        $("#uid").val(id);
        $("#name").val($("#uname"+id).html());
        $("#pwd").val($("#pwd"+id).html());
        var type=$("#type"+id).html();
        var str="";
        if(type){
          if(type==1){
            $str="<option value='1'>市级示范</option>";
          }
          if(type==2){
            $str="<option value='1'>区级示范</option>";
          }
          if(type==3){
            $str="<option value='1'>一级一类</option>";
          }
          if(type==4){
            $str="<option value='1'>一级二类</option>";
          }
          if(type==5){
            $str="<option value='1'>二级一类</option>";
          }
          if(type==6){
            $str="<option value='1'>二级二类</option>";
          }
          if(type==7){
            $str="<option value='1'>其他</option>";
          }
        }
        str+="<option value='1'>市级示范</option><option value='2'>区级示范</option><option value='3'>一级一类</option><option value='4'>一级二类</option><option value='5'>二级一类</option><option value='6'>二级二类</option><option value='7'>其他</option>";
        $("#type").html(str);
        $("#pop_wrap").css("display","block");
    }
    function doUpdateUser(){
       var uid=$("#uid").val();
       var uname=$("#name").val();
       var pwd=$("#pwd").val();
       var type=$("#type").val();
       if(uname==""){
          alert("请输入用户名");
          return;
       }
       if(pwd==""){
          alert("请输入密码");
          return;
       }
       $.ajax({
          type: "POST",
          url:"{:U('admin/Privilege/doUpdateUser')}",
          data:"uid="+uid+"&uname="+uname+"&pwd="+pwd+"&type="+type,
          dataType:"text",
          success:function(data){
            if(isNaN(data)){
              alert(data);
            }else{  
                close();
                select_filter();
            }
          }
        });
    }
    function close(){
        $("#uid").val("");
        $("#pwd").val("");
        $("#pop_wrap").css("display","none");
    }
</script>
<include file="__THEME__/public_footer" />